<html>
<head><meta charset="utf-8"><title>docs on how rustfmt works · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/docs.20on.20how.20rustfmt.20works.html">docs on how rustfmt works</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221478614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/docs%20on%20how%20rustfmt%20works/near/221478614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/docs.20on.20how.20rustfmt.20works.html#221478614">(Jan 04 2021 at 00:08)</a>:</h4>
<p>Are there any docs on how rustfmt works? I'm especially curious how it recovers comments from the source code. Thanks!</p>



<a name="221510041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/docs%20on%20how%20rustfmt%20works/near/221510041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/docs.20on.20how.20rustfmt.20works.html#221510041">(Jan 04 2021 at 10:49)</a>:</h4>
<p>I don't know myself,  but guessing, I think one way it could work is to parse the source file into an AST which has comment and doc nodes. Then convert the AST back to txt while inserting whitespace and newlines between and around nodes when necessary</p>



<a name="224432033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/docs%20on%20how%20rustfmt%20works/near/224432033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/docs.20on.20how.20rustfmt.20works.html#224432033">(Jan 29 2021 at 05:20)</a>:</h4>
<p>This looks potentially helpful: <a href="https://github.com/rust-lang/rustfmt/blob/master/Design.md#implementation-philosophy">https://github.com/rust-lang/rustfmt/blob/master/Design.md#implementation-philosophy</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>